<script lang="ts" setup>
import { onMounted } from 'vue'
import { setBimEngineConfig ,loadBimEngine,createViewer,loadProject, initBimEngineViewer, addLeftClickEvent, addModelLeftClickEvent, getViewer} from '@suit/bim-engine-tools'
import Cartesian3 from 'cesium/Source/Core/Cartesian3';

// 配置
setBimEngineConfig({
  unpkg: 'https://tech.suitbim.com/@suit/',
  baseApiUrl:"https://szsp.suitbim.com.cn:7201",
  "serviceIp": "8.153.12.127:3000",     
})

async function initEngine() {

  // const viewer = await  createViewer({
  //   container:document.getElementById('viewer')!,
  //   useUE:false,
  //   openId:"4aab7131f19e46c3bf04a7affc9d30c1",
  //  "appId": "fd281bffa3fa44fdb42603c774064d72",
  //   "secret": "043e5b75b86549159ebb2b66925f6431"
  // })
  // debugger
  // await loadProject({
  //   viewer:viewer,
  //   projectId:'4aab7131f19e46c3bf04a7affc9d30c1',
  // })

  initBimEngineViewer({
    viewerOptions:{
         container:document.getElementById('viewer')!,
       useUE:false,
       openId:"4aab7131f19e46c3bf04a7affc9d30c1",
      "appId": "fd281bffa3fa44fdb42603c774064d72",
       "secret": "043e5b75b86549159ebb2b66925f6431"
    },
    projectId:'4aab7131f19e46c3bf04a7affc9d30c1',
    // projectOpenOption:{
    //   openId:"4aab7131f19e46c3bf04a7affc9d30c1",
    // }
  })


  addLeftClickEvent(({position,entity})=>{
    console.log('addLeftClickEvent',position,entity)
  })
  addModelLeftClickEvent(({position,entity})=>{
    console.log('addModelLeftClickEvent',position,entity)
  })

  const viewer = await  getViewer()
  viewer.camera!.flyTo(new Cartesian3(0,0,0),{
    heading:0,
    pitch:0,
    roll:0
  })
}
onMounted(()=>{
  initEngine()
})


</script>
<template>
  <div style="width: 100%; height: 100%;">
    <div id="viewer" style="width: 100%; height: 100%;"></div>
  </div>
</template>
